<template>
	<view id="sample-info">
		<view class="list">
			<uni-list>
				<uni-list-item title="原材料" :rightText="materialName" />
				<uni-list-item 
					v-for="(item,index) in formList" 
					:title="item.name" 
					:rightText="item.value" 
				/>
			</uni-list>
		</view> 
		<view class="bottom-nav">
			<button type="primary" class="btn" :loading="loading" @click="next">完成</button>
		</view>
	</view>
</template>

<script>
import { save, getFormField, getOptions } from '@/api/sampleCheck/index'
	
export default {
	data(){
		return {
			// 是否同步数据
			networkFlag: false,
			materialName: '',
			sampleCheck: {},
			loading: false,
			formList: []
		}
	},
	onLoad(param) {
		this.networkFlag = param.flag
		this.sampleCheck = uni.getStorageSync('sampleCheck')
		console.log(this.sampleCheck)
		this.getFormField(this.sampleCheck.qrCode)
	},
	methods: {
		// 获取表单信息
		getFormField(code) {
			getFormField(code).then(res=>{
				this.formList = res.data.formFillValues
				let id = uni.getStorageSync('projectInfo').id 
				let data = {
				projectId:id
			}
			getOptions(data).then(result=>{
					result.rows.forEach(item=>{
						console.log(item)
						console.log(res.data.materialId)
						if (item.id == res.data.materialId) {
							this.materialName = item.name
						}
					})
				})
			})
		},
		next() {
			this.loading = true
			save(this.sampleCheck).then(res=>{
				this.loading = false
				if (res.code == 200) {
					if (this.networkFlag) {
						uni.removeStorageSync('networkCheck')
					}
					uni.showToast({
						title: "上传成功",
						duration: 1500
					})
					uni.navigateTo({
						url: '/pages/menu/index'
					})
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			})
		}
	},
}
</script>

<style lang="scss" scoped>
#sample-info {
	.list {
		padding: 10px;
		overflow-y: auto;
		height: calc(100vh - 50px);
		
		.content {
			padding: 0 20px 10px 20px;
		}
		/deep/ .uni-list-item__container {
			padding: 8px;
		}
		/deep/ .uni-list-item__content {
			justify-content: center;
		}
		/deep/ .uni-list-item__content {
			flex: 0 0 auto;
		}
		/deep/ .uni-list-item__extra {
			flex: 1 1 auto;
		}
	}
	.bottom-nav {
		left: 0;
		bottom: 0;
		width: 100vw;
		height: 50px;
		padding: 10px;
		position: fixed;
		background-color: #fff;
		box-shadow: 0px 0px 5px 1px rgba(0, 0, 0, .1);
	}
}
</style>
